package com.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ydd.dto.AdvimgDTO;
import com.ydd.dto.AdvimgPageQueryDTO;
import com.ydd.entity.YddAdvimg;
import com.ydd.mapper.YddAdvimgMapper;
import com.ydd.result.PageResult;
import com.ydd.service.YddAdvimgService;
import com.ydd.vo.AdvimgVO;
import com.ydd.vo.AdvposVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:31
 */
@Service
public class YddAdvimgServiceImpl implements YddAdvimgService {
    @Autowired
    private YddAdvimgMapper yddAdvimgMapper;

    @Override
    public PageResult page(AdvimgPageQueryDTO advimgPageQueryDTO) {
        Integer page = advimgPageQueryDTO.getPage();
        Integer limit = advimgPageQueryDTO.getLimit();
        //设置分页数据
        PageHelper.startPage(page, limit);
        //调用方法
        List<AdvimgVO> list = yddAdvimgMapper.page(advimgPageQueryDTO);
        //转换成Page类型
        Page<AdvimgVO> advimgVOS = (Page<AdvimgVO>) list;


        return new PageResult(advimgVOS.getTotal(),
                advimgVOS.getPageNum(),
                advimgVOS.getPageSize(),
                advimgVOS.getPages(),
                list);
    }


    /**
     * 根据ID查询广告图详情
     * @param id
     * @return
     */
    @Override
    public YddAdvimg selectById(String id) {
        YddAdvimg yddAdvimg = yddAdvimgMapper.selectById(id);
        return yddAdvimg;
    }

    /**
     * 广告图修改
     * @param yddAdvimg
     */
    @Override
    public void update(YddAdvimg yddAdvimg) {
        yddAdvimgMapper.updateById(yddAdvimg);
    }

    /**
     * 广告图添加
     * @param yddAdvimg
     */
    @Override
    public void add(YddAdvimg yddAdvimg) {
        yddAdvimgMapper.insert(yddAdvimg);
    }

    /**
     * 广告图删除
     * @param id
     */
    @Override
    public void delete(String id) {
        LambdaQueryWrapper<YddAdvimg> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YddAdvimg::getId,id);

        yddAdvimgMapper.deleteById(id);
    }
}
